<template>

  <div class="mycenter-in-box" v-if="dataMudel && userInfomation">
    <p class="mycenter-in-box-title">数据精灵</p>
    <!--总数据-->
    <powerTop :statisticsData="statisticsData" v-if="powerArrayFn(userInfomation,'powerTop')"></powerTop>
    <!--图书管理员-->
    <powerBook :statisticsData="statisticsData" v-if="powerArrayFn(userInfomation,'powerBook')"></powerBook>
    <!--物料管理员-->
    <powerMateriel :statisticsData="statisticsData"
                   v-if="powerArrayFn(userInfomation,'powerMateriel')"></powerMateriel>
    <!--教具管理员-->
    <powerTeacher :statisticsData="statisticsData" v-if="powerArrayFn(userInfomation,'powerTeacher')"></powerTeacher>
    <!--餐饮管理员-->
    <powerFood :statisticsData="statisticsData" v-if="powerArrayFn(userInfomation,'powerFood')"></powerFood>
    <!--区角管理员-->
    <powerCorner :statisticsData="statisticsData" v-if="powerArrayFn(userInfomation,'powerCorner')"></powerCorner>
    <!--论坛管理员-->
    <powerForum :statisticsData="statisticsData" v-if="plateList.length"></powerForum>
  </div>
</template>

<script>
  import powerTop from '@/components/power/powerTop'
  import powerBook from '@/components/power/powerBook'
  import powerMateriel from '@/components/power/powerMateriel'
  import powerTeacher from '@/components/power/powerTeacher'
  import powerForum from '@/components/power/powerForum'
  import powerCorner from '@/components/power/powerCorner'
  import powerFood from '@/components/power/powerFood'
  import {powerArrayFn} from '@/components/power.js'
  import {mapActions} from "vuex";

  export default {
    props: [],
    components: {
      powerTop,
      powerBook,
      powerMateriel,
      powerTeacher,
      powerForum,
      powerCorner,
      powerFood
    },
    name: 'powerIndex',
    data () {
      return {
        dataMudel: false,
        powerArrayFn: powerArrayFn,
        userInfomation: null,
        userInfo: null,
        countNumber: null,
        uerPower: null,
        statisticsData: null,
        powerList: null,
        plateList: []
      }
    },
    created () {
      // is_all 总管理员8
      // n7-3  教具管理员； n6-3 图书管理员；n9-3 物料管理员； n12-1-3 餐品管理员；
      // this.InitFn()
      this.GetInfo().then(res=>{
        this.userInfomation = res.detail
        this.powerList = res.detail.power?JSON.parse(res.detail.power):null
        // this.InitFn()
        this.statisticsFn()
        this.forumFn()
      })
    },
    methods: {
      ...mapActions(['GetInfo']),
      InitFn () {
        this.$fetch(this.api.admin_user_edit, {
          id: this.userInfomation.id
        }).then((response) => {
          if (response.code === 0) {
            let obj = {}
            obj.pic = response.detail.pic
            this.global.userInfoFn(2, obj)
            this.userInfo = response.detail
            this.countNumber = response.count
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      forumFn () {
        this.$fetch(this.api.admin_user_detail, {}).then((response) => {
          if (response.code === 0) {
            if (response.plate) {
              this.plateList = response.plate
            }
            this.dataMudelStateFn()
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      statisticsFn () {
        this.$fetch(this.api.statistics, {}).then((response) => {
          if (response.code === 0) {
            this.statisticsData = response
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      dataMudelStateFn () {
        if (this.plateList.length || powerArrayFn(this.userInfomation, 'powerTeacher') || powerArrayFn(this.userInfomation, 'powerMateriel') || powerArrayFn(this.userInfomation, 'powerBook') || powerArrayFn(this.userInfomation, 'powerTop')) {
          this.dataMudel = true
        }
      }
    }
  }
</script>
